package com.device.grant.dao.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.device.grant.dao.ApparatusDao;
import com.device.grant.dao.BaseDao;
import com.device.grant.pojo.Apparatus;
import com.device.grant.utils.ColumnCompator;
import com.device.grant.utils.SQLUtils2;

@Repository("apparatusDao")
public class ApparatusDaoImpl extends BaseDao<Apparatus> implements ApparatusDao {

	private static final String	ID		= "appCode";

	private static final String	TABLE	= "Apparatus";

	public boolean addApparatus(Apparatus apparatus) {
		return super.insert(TABLE, ID, apparatus);
	}

	public boolean updateApparatus(Map<String, Object> changeInfos, Map<String, Object> conditions) {
		return super.update(TABLE, changeInfos, conditions);
	}

	public boolean updateApparatusByBean(Apparatus apparatus) {
		Map<String, Object> map = SQLUtils2.generalUpdateSQLFromBean(apparatus, ID, TABLE);

		int result = simpleJdbcTemplate.update(map.get(SQLUtils2.SQL).toString(), (Object[]) map.get(SQLUtils2.PARAMS));
		 
		return (result < 0) ? false : true;
	}

	public List<Apparatus> queryApparatus(Integer page, Integer rows, Map<String, Object> params, List<String> blearParams,
			Map<String, ColumnCompator> compators, String orderBy) {
		String sql = SQLUtils2.genearlQuerySQLForCompareAndNotIn(TABLE, ID, page, rows, params, blearParams, compators, orderBy);

		return super.queryInSQL(sql);
	}

	public Integer countApparatus(Map<String, Object> conditions, List<String> blearParams, Map<String, ColumnCompator> compators) {
		Map<String, Object> map = SQLUtils2.generalCountSQLForCompare(TABLE, ID, conditions, blearParams, compators);

		return simpleJdbcTemplate.queryForInt(map.get(SQLUtils2.SQL).toString(), (Object[]) map.get(SQLUtils2.PARAMS));
	}

	public Apparatus getTheApparatus(Map<String, Object> conditions) {
		return super.get(TABLE, conditions);
	}

	public List<Apparatus> queryApparatusInGroup(Map<String, Object> conditions) {
		return super.queryAllInCoditions(TABLE, null, conditions);
	}

	public List<Apparatus> queryApparatusByIds(Set<Integer> ids) {
		return super.queryInKeys(TABLE, ID, null, ids);
	}
}
